Merge branch 'master' into attempt
authorNipunn Koorapati <nipunn@dropbox.com>
Tue, 15 Nov 2016 19:53:24 +0000 (11:53 -0800)
committerNipunn Koorapati <nipunn@dropbox.com>
Tue, 15 Nov 2016 19:53:29 +0000 (11:53 -0800)
- Fix instances of try! converting to ? syntax

1  2 
src/cargo/ops/cargo_clean.rs
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/fingerprint.rs
src/cargo/ops/cargo_rustc/layout.rs
src/cargo/ops/cargo_rustc/mod.rs
tests/freshness.rs
tests/test.rs

index 738417a4bf83184603ea7bc9ead226282ba86855,4f6e6cf03531cbfc91430553d3cdb49554030037..99b45f7c20a936aed1ce054024e5a2774f2c092d
@@@ -74,14 -74,12 +74,14 @@@ pub fn clean(ws: &Workspace, opts: &Cle
  
      for unit in units.iter() {
          let layout = cx.layout(unit);
-         try!(rm_rf(&layout.proxy().fingerprint(&unit.pkg)));
-         try!(rm_rf(&layout.build(&unit.pkg)));
+         rm_rf(&layout.proxy().fingerprint(&unit.pkg))?;
+         rm_rf(&layout.build(&unit.pkg))?;
  
-         for (src, link_dst, _) in try!(cx.target_filenames(&unit)) {
-             try!(rm_rf(&src));
 -        let root = cx.out_dir(&unit);
 -        for (filename, _) in cx.target_filenames(&unit)? {
 -            rm_rf(&root.join(&filename))?;
++        for (src, link_dst, _) in cx.target_filenames(&unit)? {
++            rm_rf(&src)?;
 +            if let Some(dst) = link_dst {
-                 try!(rm_rf(&dst));
++                rm_rf(&dst)?;
 +            }
          }
      }
  
Simple merge
index 1f785609fd589ebf4a41f8ee6e78cfc343c98dad,ae0497e716d46bf1f6508a7f1fb03f64e1279c7d..6cc8f88c105a44a9ce4f8746bacc0caf137afad6
@@@ -82,11 -82,8 +82,11 @@@ pub fn prepare_target<'a, 'cfg>(cx: &mu
          missing_outputs = !root.join(unit.target.crate_name())
                                 .join("index.html").exists();
      } else {
-         for (src, link_dst, _) in try!(cx.target_filenames(unit)) {
 -        for (filename, _) in cx.target_filenames(unit)? {
 -            missing_outputs |= fs::metadata(root.join(filename)).is_err();
++        for (src, link_dst, _) in cx.target_filenames(unit)? {
 +            missing_outputs |= !src.exists();
 +            if let Some(link_dst) = link_dst {
 +                missing_outputs |= !link_dst.exists();
 +            }
          }
      }
  
Simple merge
index 435f28f5c2e3b57df1e7e9e3155460e240f71ab3,a7aedbe6b755a7541024d70eb27cff841d43571f..02e1088303b9bb297f3356b1b513568724a70dd9
@@@ -110,12 -110,8 +110,12 @@@ pub fn compile_targets<'a, 'cfg: 'a>(ws
            .or_insert(Vec::new())
            .push(("OUT_DIR".to_string(), out_dir));
  
-         for (dst, link_dst, _linkable) in try!(cx.target_filenames(unit)) {
 -        for (filename, _linkable) in cx.target_filenames(unit)? {
 -            let dst = cx.out_dir(unit).join(filename);
++        for (dst, link_dst, _linkable) in cx.target_filenames(unit)? {
 +            let bindst = match link_dst {
 +                Some(link_dst) => link_dst,
 +                None => dst.clone(),
 +            };
 +
              if unit.profile.test {
                  cx.compilation.tests.push((unit.pkg.clone(),
                                             unit.target.name().to_string(),
                      continue
                  }
  
-                 let v = try!(cx.target_filenames(unit));
+                 let v = cx.target_filenames(unit)?;
 -                let v = v.into_iter().map(|(f, _)| {
 -                    (unit.target.clone(), cx.out_dir(unit).join(f))
 +                let v = v.into_iter().map(|(f, _, _)| {
 +                    (unit.target.clone(), f)
                  }).collect::<Vec<_>>();
                  cx.compilation.libraries.insert(pkgid.clone(), v);
              }
@@@ -177,27 -173,23 +177,27 @@@ fn compile<'a, 'cfg: 'a>(cx: &mut Conte
      // we've got everything constructed.
      let p = profile::start(format!("preparing: {}/{}", unit.pkg,
                                     unit.target.name()));
-     try!(fingerprint::prepare_init(cx, unit));
-     try!(cx.links.validate(unit));
+     fingerprint::prepare_init(cx, unit)?;
+     cx.links.validate(unit)?;
  
      let (dirty, fresh, freshness) = if unit.profile.run_custom_build {
-         try!(custom_build::prepare(cx, unit))
+         custom_build::prepare(cx, unit)?
      } else {
-         let (freshness, dirty, fresh) = try!(fingerprint::prepare_target(cx,
-                                                                          unit));
+         let (freshness, dirty, fresh) = fingerprint::prepare_target(cx,
+                                                                          unit)?;
          let work = if unit.profile.doc {
-             try!(rustdoc(cx, unit))
+             rustdoc(cx, unit)?
          } else {
-             try!(rustc(cx, unit))
+             rustc(cx, unit)?
          };
-         let link_work1 = try!(link_targets(cx, unit));
-         let link_work2 = try!(link_targets(cx, unit));
 -        let dirty = work.then(dirty);
++        let link_work1 = link_targets(cx, unit)?;
++        let link_work2 = link_targets(cx, unit)?;
 +        // Need to link targets on both the dirty and fresh
 +        let dirty = work.then(link_work1).then(dirty);
 +        let fresh = link_work2.then(fresh);
          (dirty, fresh, freshness)
      };
-     try!(jobs.enqueue(cx, unit, Job::new(dirty, fresh), freshness));
+     jobs.enqueue(cx, unit, Job::new(dirty, fresh), freshness)?;
      drop(p);
  
      // Be sure to compile all dependencies of this target as well.
@@@ -265,11 -257,12 +265,11 @@@ fn rustc(cx: &mut Context, unit: &Unit
  
          // FIXME(rust-lang/rust#18913): we probably shouldn't have to do
          //                              this manually
 -        for &(ref filename, _linkable) in filenames.iter() {
 -            let dst = root.join(filename);
 +        for &(ref dst, ref _link_dst, _linkable) in filenames.iter() {
              if fs::metadata(&dst).is_ok() {
-                 try!(fs::remove_file(&dst).chain_error(|| {
+                 fs::remove_file(&dst).chain_error(|| {
                      human(format!("Could not remove file: {}.", dst.display()))
-                 }));
+                 })?;
              }
          }
  
              rustc.exec()
          }.chain_error(|| {
              human(format!("Could not compile `{}`.", name))
-         }));
+         })?;
  
          if do_rename && real_name != crate_name {
 -            let dst = root.join(&filenames[0].0);
 +            let dst = &filenames[0].0;
              let src = dst.with_file_name(dst.file_name().unwrap()
                                              .to_str().unwrap()
                                              .replace(&real_name, &crate_name));
          }
  
          if !has_custom_args || fs::metadata(&rustc_dep_info_loc).is_ok() {
-             try!(fs::rename(&rustc_dep_info_loc, &dep_info_loc).chain_error(|| {
 +            info!("Renaming dep_info {:?} to {:?}", rustc_dep_info_loc, dep_info_loc);
+             fs::rename(&rustc_dep_info_loc, &dep_info_loc).chain_error(|| {
                  internal(format!("could not rename dep info: {:?}",
                                rustc_dep_info_loc))
-             }));
-             try!(fingerprint::append_current_dir(&dep_info_loc, &cwd));
+             })?;
+             fingerprint::append_current_dir(&dep_info_loc, &cwd)?;
          }
  
 -        // If we're a "root crate", e.g. the target of this compilation, then we
 -        // hard link our outputs out of the `deps` directory into the directory
 -        // above. This means that `cargo build` will produce binaries in
 -        // `target/debug` which one probably expects.
 -        if move_outputs_up {
 -            for &(ref filename, _linkable) in filenames.iter() {
 -                let src = root.join(filename);
 -                // This may have been a `cargo rustc` command which changes the
 -                // output, so the source may not actually exist.
 -                if !src.exists() {
 -                    continue
 -                }
 -
 -                // We currently only lift files up from the `deps` directory. If
 -                // it was compiled into something like `example/` or `doc/` then
 -                // we don't want to link it up.
 -                let src_dir = src.parent().unwrap();
 -                if !src_dir.ends_with("deps") {
 -                    continue
 -                }
 -                let dst = src_dir.parent().unwrap()
 -                                 .join(src.file_name().unwrap());
 -                if dst.exists() {
 -                    fs::remove_file(&dst).chain_error(|| {
 -                        human(format!("failed to remove: {}", dst.display()))
 -                    })?;
 -                }
 -                fs::hard_link(&src, &dst)
 -                     .or_else(|_| fs::copy(&src, &dst).map(|_| ()))
 -                     .chain_error(|| {
 -                         human(format!("failed to link or copy `{}` to `{}`",
 -                                       src.display(), dst.display()))
 -                })?;
 -            }
 -        }
 -
          Ok(())
      }));
  
      }
  }
  
-     let filenames = try!(cx.target_filenames(unit));
 +/// Link the compiled target (often of form foo-{metadata_hash}) to the
 +/// final target. This must happen during both "Fresh" and "Compile"
 +fn link_targets(cx: &mut Context, unit: &Unit) -> CargoResult<Work> {
-                 try!(fs::remove_file(&dst).chain_error(|| {
++    let filenames = cx.target_filenames(unit)?;
 +    Ok(Work::new(move |_| {
 +        // If we're a "root crate", e.g. the target of this compilation, then we
 +        // hard link our outputs out of the `deps` directory into the directory
 +        // above. This means that `cargo build` will produce binaries in
 +        // `target/debug` which one probably expects.
 +        for (src, link_dst, _linkable) in filenames {
 +            // This may have been a `cargo rustc` command which changes the
 +            // output, so the source may not actually exist.
 +            debug!("Thinking about linking {} to {:?}", src.display(), link_dst);
 +            if !src.exists() || link_dst.is_none() {
 +                continue
 +            }
 +            let dst = link_dst.unwrap();
 +
 +            debug!("linking {} to {}", src.display(), dst.display());
 +            if dst.exists() {
-                 }));
++                fs::remove_file(&dst).chain_error(|| {
 +                    human(format!("failed to remove: {}", dst.display()))
-             try!(fs::hard_link(&src, &dst)
++                })?;
 +            }
-             }));
++            fs::hard_link(&src, &dst)
 +                 .or_else(|err| {
 +                     debug!("hard link failed {}. falling back to fs::copy", err);
 +                     fs::copy(&src, &dst).map(|_| ())
 +                 })
 +                 .chain_error(|| {
 +                     human(format!("failed to link or copy `{}` to `{}`",
 +                                   src.display(), dst.display()))
++            })?;
 +        }
 +        Ok(())
 +    }))
 +}
 +
  fn load_build_deps(cx: &Context, unit: &Unit) -> Option<Arc<BuildScripts>> {
      cx.build_scripts.get(unit).cloned()
  }
@@@ -668,7 -658,7 +668,7 @@@ fn build_deps_args(cmd: &mut ProcessBui
  
      fn link_to(cmd: &mut ProcessBuilder, cx: &Context, unit: &Unit)
                 -> CargoResult<()> {
-         for (dst, _link_dst, linkable) in try!(cx.target_filenames(unit)) {
 -        for (filename, linkable) in cx.target_filenames(unit)? {
++        for (dst, _link_dst, linkable) in cx.target_filenames(unit)? {
              if !linkable {
                  continue
              }
Simple merge
diff --cc tests/test.rs
Simple merge